<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('公示公告') }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true" @submit.native.prevent>
      <el-form-item :label="$t('基金名称')" prop="name">
        <MainBodySelect
          v-model="queryParams.fundId"
          parameters="fund"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t("搜索") }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t("重置") }}</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['lp:LpPublicBulletin:edit']"
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="addHandle"
        >{{ $t("新增") }}</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['lp:LpPublicBulletin:edit']"
          type="warning"
          size="mini"
          icon="el-icon-setting"
          @click="openTemplate"
        >{{ $t("模板维护") }}</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="lpPublicBulletinList" border>
      <el-table-column :label="$t('公告标题')" align="center" prop="title" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <el-link class="link-a" type="primary" :underline="false" @click="updateHandle(scope.row)">{{ scope.row.title }}</el-link>
        </template>
      </el-table-column>
      <el-table-column :label="$t('基金名称')" align="center" prop="fundName" show-overflow-tooltip />
      <el-table-column :label="$t('公告类型')" align="center" prop="type" :formatter="fundTypeFormat" width="120" show-overflow-tooltip />
      <el-table-column :label="$t('状态')" align="center" prop="status" width="120" show-overflow-tooltip>
        <template slot-scope="scope">
          <span :style="{ color: (scope.row.status === '已驳回' ? 'red' : '') }">{{ formatStatus(scope.row.status) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('操作')" fixed="right" align="center" class-name="small-padding fixed-width" width="150">
        <template slot-scope="scope">
          <el-button
            v-hasPermi="['lp:LpPublicBulletin:edit']"
            size="small"
            type="text"
            icon="el-icon-edit"
            @click="updateHandle(scope.row)"
          >{{ $t('修改') }}</el-button>
          <el-button
            v-hasPermi="['lp:LpPublicBulletin:edit']"
            size="small"
            type="text"
            icon="el-icon-delete"
            @click="deleteHandle(scope.row)"
          >{{ $t('删除') }}</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <el-dialog :title="$t('公示公告')" :visible.sync="formOpen" :destroy-on-close="true" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <afficheForm v-if="formOpen" ref="afficheForm" />
    </el-dialog>
    <!-- 打开模板维护list-->
    <el-dialog :title="title" :visible.sync="templateOpen" :destroy-on-close="true" :close-on-click-modal="false" :lock-scroll="false" custom-class="sysTypeTabs" append-to-body>
      <afficheTemplateList v-if="templateOpen" ref="templateRef" />
    </el-dialog>
  </div>
</template>

<script>
import MainBodySelect from '@/components/MainBodySelect/index'
import afficheForm from './afficheForm.vue'
import afficheTemplateList from '@/views/fund/lpBase/lp/afficheTemplateList.vue'
import { findListReviewed, delLpPublicBulletin } from '@/api/fund/lpBase/lp/affiche/affiche.js'
import { listLpAnnouncementTemplate } from '@/api/fund/lpBase/lp/affiche/afficheListTemplate'
export default {
  components: {
    afficheForm,
    afficheTemplateList,
    MainBodySelect
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 公示公告表格数据
      lpPublicBulletinList: [],
      formOpen: false,
      // 查询参数
      queryParams: {
        fundId: '',
        pageNum: 1,
        pageSize: 10
      },
      //
      title: '',
      // 模板
      templateOpen: false,
      lpTemplate: []
    }
  },
  created() {
    // 获取公告类型
    listLpAnnouncementTemplate().then(response => {
      response.rows.forEach(item => {
        this.lpTemplate.push({ dictValue: item.id, dictLabel: item.name })
      })
    })
    this.getList()
  },
  methods: {
    /** 查询公示公告列表 */
    getList() {
      this.loading = true
      findListReviewed(this.queryParams).then(response => {
        this.lpPublicBulletinList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 类型字典回显
    fundTypeFormat(row) {
      return this.selectDictLabel(this.lpTemplate, row.type)
    },
    // 格式化状态
    formatStatus(status) {
      if (status === undefined || status === '' || status === null) {
        return this.$t('未复核')
      } else {
        return this.$t(status)
      }
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        fundId: undefined,
        type: undefined,
        period: undefined,
        fundScale: undefined,
        callProp: undefined,
        callMoney: undefined,
        subscribedAmount: undefined,
        title: undefined,
        context: undefined,
        remarks: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined,
        delFlag: undefined
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.fundId = ''
      this.resetForm('queryForm')
      this.queryHandle()
    },
    /** 新增按钮操作 */
    addHandle() {
      this.formOpen = true
      this.title = this.$t('公式公告')
      this.$nextTick(() => {
        this.$refs.afficheForm.init(null)
      })
    },
    /** 修改按钮操作 */
    updateHandle(row) {
      this.formOpen = true
      this.$nextTick(() => {
        // 调用form页面的 init 方法初始化数据
        this.$refs.afficheForm.init(row)
      })
    },
    /** 删除按钮操作 */
    deleteHandle(row) {
      this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
        confirmButtonText: this.$t('确定'),
        cancelButtonText: this.$t('取消'),
        type: 'warning'
      }).then(function() {
        return delLpPublicBulletin(row.id)
      }).then(() => {
        this.getList()
        this.msgSuccess(this.$t('删除成功'))
      }).catch(function() {
      })
    },
    // da开模板维护list
    openTemplate() {
      this.templateOpen = true
      this.$nextTick(() => {
        this.title = this.$t('模板维护')
      })
    }
  }

}
</script>
